#include "stm32f10x.h"
#include "stm32f10x_it.h"
#include "led.h"
#include "delay.h"
#include "usart.h"
#include "stdio.h"
#include "key.h"
#include "oled.h"
#include "hw.h"
#include "motor.h"
#include "adc.h"

uint16_t ADValue;
float Voltage;

int main(void)
{

	NVIC_PriorityGroupConfig(NVIC_PriorityGroup_2);
	LED_Init();
	USART_init(115200);
	Delay_Init();
	KEY_Init();
	OLED_Init();
	hw_init();
	MotorAll_Init();
	Adc_Init();


	while(1){
//		if (HW == 0){
//		Car_Stop();
//		GPIO_ResetBits(GPIOC, GPIO_Pin_13);
//		Delay_ms(50);
//		GPIO_SetBits(GPIOC, GPIO_Pin_13);
//		Delay_ms(50);
//		}


		OLED_Clear();
		if (get_key4_value()==0){
			uint8_t cmd[] = "cmd:station mode";
			OLED_ShowString(0,0,cmd,16,1);
		}
		else if (get_key4_value()==1){
			uint8_t cmd[] = "cmd:connect wifi";
			OLED_ShowString(0,0,cmd,16,1);
		}
		else if (get_key4_value()==2){
			uint8_t cmd[] = "cmd:connect tcp";
			OLED_ShowString(0,0,cmd,16,1);
		}

		OLED_ShowChinese(0,20,5,16,1);
		OLED_ShowChinese(20,20,6,16,1);
		uint8_t colon[] = ":";
		OLED_ShowString(38,20,colon ,16,1);
		set_car_speed();
		
		ADValue = ADC_GetValue();
    Voltage = (float)ADValue/4095*3.3;
		OLED_ShowNum(0,40,ADValue,4,16,1);
		OLED_ShowNum(50,40,Voltage,1,16,1);
    OLED_ShowNum(80,40,(uint16_t)(Voltage*100)%100,2,16,1);
		OLED_Refresh();
	}
}
